import { useState } from 'react';
import { v7 as uuidv7 } from 'uuid';

export default function useBasePage<T>() {
  const [total, setTotal] = useState(0);
  const [pageNum, setPageNum] = useState(1);
  const [pageSize, setPageSize] = useState(10);
  const [tableData, setTableData] = useState<T[]>([]);
  const [tableReFresh, setTableReFresh] = useState(null);
  const refreshTableById = () => {
    setTableReFresh(uuidv7());
  };

  const resetPageData = () => {
    setPageNum(1);
    setPageSize(10);
  };

  return {
    total,
    setTotal,
    pageNum,
    setPageNum,
    pageSize,
    setPageSize,
    tableReFresh,
    refreshTableById,
    tableData,
    setTableData,
    resetPageData,
  };
}
